<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>分类检测前端</title>
</head>
<body>
    <h1>分类检测结果</h1>
    <div id="result">等待检测...</div>
    <script>
        // const url = "http://127.0.0.1:18888/predict"
        const url = "http://192.168.1.5:18888/predict"
        async function fetchPrediction() {
            try {
                const response = await fetch(url);
                const data = await response.json();
                if (data.error) {
                    document.getElementById("result").innerText = data.error;
                } else {
                    document.getElementById("result").innerText =
                        `分类: ${data.class}, 置信度: ${data.confidence}`;
                    // 根据分类结果执行逻辑操作
                    if (data.class === 1) {
                        console.log("执行某些逻辑操作");
                    }
                }
            } catch (err) {
                console.error("请求失败", err);
            }
        }

        setInterval(fetchPrediction, 1000);  // 每秒调用一次
    </script>
</body>
</html>
